// @author: caoshi
// @date: 2021-05-05 13:40
// 数据库操作工具类

package util

import (
	"database/sql"
	"fmt"
	"strconv"
)

// 数据库连接基本信息
var (
	username = "root"
	password = "hadoop123"
	host = "121.196.166.188"
	port = 3306
)

func GetDb(daName string) *sql.DB {
	dataSourceName := username + ":" + password + "@tcp(" + host + ":" + strconv.Itoa(port) + ")/" + daName
	db, err := sql.Open("mysql", dataSourceName)
	if err != nil {
		fmt.Println("连接数据库失败!")
		return nil
	}
	return db
}

func GetStmt(db *sql.DB, sql string) *sql.Stmt {
	stmt, err := db.Prepare(sql)
	if err != nil {
		fmt.Println("获取预处理对象失败!")
		return nil
	}
	return stmt
}










